package com.sky.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext;
import com.sky.dto.*;
import com.sky.entity.*;
import com.sky.exception.AddressBookBusinessException;
import com.sky.exception.OrderBusinessException;
import com.sky.mapper.*;
import com.sky.result.PageResult;
import com.sky.service.OrderService;
import com.sky.service.ShoppingCartService;
import com.sky.utils.WeChatPayUtil;
import com.sky.vo.*;
import com.sky.webSocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 订单
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {


    @Autowired
    private AddressBookMapper addressBookMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private WeChatPayUtil weChatPayUtil;
    @Autowired
    private OrderService orderService;

    //webSocket相关
    @Autowired
    private WebSocketServer webSocketServer;


    @Override
    @Transactional
    public OrderSubmitVO submit(OrdersSubmitDTO ordersSubmitDTO) {

        //根据id查询默认的地址
        AddressBook addressBook = addressBookMapper.selectById(ordersSubmitDTO.getAddressBookId());
        if (addressBook == null) {
            throw  new AddressBookBusinessException("当前未设置默认地址");
        }

        //完善订单表
        Orders orders = new Orders();
        BeanUtils.copyProperties(ordersSubmitDTO, orders);
        orders.setNumber(System.currentTimeMillis()+"");
        //设置订单的状态 6种
        orders.setStatus(Orders.PENDING_PAYMENT);
        Long userId = BaseContext.getCurrentId();
        orders.setUserId(userId);
        orders.setOrderTime(LocalDateTime.now());
        //设置订的状态 3种
        orders.setPayStatus(Orders.UN_PAID);

        orders.setPhone(addressBook.getPhone());
        //只获得详细地址
        orders.setAddress(addressBook.getDetail());
        //用户名先用地址的那个收件人填写
        //orders.setUserName(addressBook.getConsignee());

        orders.setConsignee(addressBook.getConsignee());

        orderMapper.insert(orders);

        //完善订单详情表
        List<OrderDetail> orderDetailList = new ArrayList<>();
        //查询购物车

        List<ShoppingCart> shoppingCartList = shoppingCartMapper.list(userId);

        shoppingCartList.forEach(shoppingCart -> {
            OrderDetail orderDetail = new OrderDetail();

            BeanUtils.copyProperties(shoppingCart, orderDetail,"id");
            //补充属性
            orderDetail.setOrderId(orders.getId());
            orderDetailList.add(orderDetail);

        });

        //进行批量插入
        orderDetailMapper.insertBatch(orderDetailList);

        //清除购物车
        shoppingCartMapper.deleteAllById(userId);


        //返回封装结果

        OrderSubmitVO orderSubmitVO = OrderSubmitVO.builder()
                .orderNumber(orders.getNumber())
                .orderTime(orders.getOrderTime())
                .orderAmount(orders.getAmount()).build();
        return orderSubmitVO;


    }


    /**
     * 用户订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @Override
    public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        /*// 当前登录用户id
        Long userId = BaseContext.getCurrentId();
        User user = userMapper.getById(userId);

        //关闭接口
        //调用微信支付接口，生成预支付交易单
        JSONObject jsonObject = weChatPayUtil.pay(
                ordersPaymentDTO.getOrderNumber(), //商户订单号
                new BigDecimal(0.01), //支付金额，单位 元
                "苍穹外卖订单", //商品描述
                user.getOpenid() //微信用户的openid
        );

        if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("ORDERPAID")) {
            throw new OrderBusinessException("该订单已支付");
        }

        OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
        vo.setPackageStr(jsonObject.getString("package"));

        return vo;*/


        ///   ////////////////////////////////////////////////////////////

        //模拟支付成功！！ -- 修改订单状态

        orderService.paySuccess(ordersPaymentDTO.getOrderNumber());

        return new OrderPaymentVO();

            }

    /**
     * 支付成功，修改订单状态
     *
     * @param outTradeNo
     */
    public void paySuccess(String outTradeNo) {
        // 当前登录用户id
        Long userId = BaseContext.getCurrentId();

        // 根据订单号查询当前用户的订单
        Orders ordersDB = orderMapper.getByNumberAndUserId(outTradeNo, userId);

        // 根据订单id更新订单的状态、支付方式、支付状态、结账时间
        Orders orders = Orders.builder()
                .id(ordersDB.getId())
                .status(Orders.TO_BE_CONFIRMED)
                .payStatus(Orders.PAID)
                .checkoutTime(LocalDateTime.now())
                .build();

        orderMapper.update(orders);

        //在用户付完款之后，将微信小程序端的数据订单信息推送给后台的管理系统
        /// ////////////////////////////////////////
        //1.使用map进行消息封装
        Map map = new HashMap();

        map.put("type", 1);//1为来电提醒
        map.put("orderId", orders.getId());
        map.put("content", "订单号："+ outTradeNo);

        //2. 通过websocket进行群发消息发送到后台管理系统
        webSocketServer.sendToAllClient(JSONObject.toJSONString(map));
        /// /////////////////////////////////////////


        
    }

    @Override
    public PageResult page(Integer page, Integer pageSize, Integer status) {
        PageHelper.startPage(page, pageSize);

        //只能查询自己的订单
        OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
        ordersPageQueryDTO.setStatus(status);
        ordersPageQueryDTO.setUserId(BaseContext.getCurrentId());

        //最终返回的
        ArrayList<OrderVO> orderVOS = new ArrayList<>();


        Page<Orders> orderList = orderMapper.list(ordersPageQueryDTO);

        if (orderList != null || orderList.getTotal() != 0) {
            orderList.forEach(order -> {
                //补充订单详情信息
                List<OrderDetail> orderDetailList = orderDetailMapper.selectByOrderId(order.getId());

                OrderVO orderVO = new OrderVO();

                BeanUtils.copyProperties(order, orderVO);
                orderVO.setOrderDetailList(orderDetailList);
                orderVOS.add(orderVO);

            });
        }

        //orderList.getResult()信息不全
        return new PageResult(orderList.getTotal(),orderVOS);
    }

    @Override
    public OrderVO getOrderDetailById(Long id) {
        Orders orders = orderMapper.getById(id);
        OrderVO orderVO = new OrderVO();
        BeanUtils.copyProperties(orders, orderVO);
        List<OrderDetail> orderDetailList = orderDetailMapper.selectByOrderId(orderVO.getId());
        orderVO.setOrderDetailList(orderDetailList);
        //没有设置orderDishes这个字段，后续还有进行补充

        return orderVO;
    }

    /**
     * 用户取消订单
     * @param id
     */
    @Override
    public void cancelOrder(Long id) throws Exception {
        Orders orders = orderMapper.getById(id);

        //首先判断订单是否存在
        if (orders == null) {
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);

        }
        // 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消
        // 用户端取消订单，只能取消还未接单的订单，其他情况取消订单，需要联系商家在后台取消
        //判断订单是否在派送中，派送中的订单只能后台商家进行取消
        if (orders.getStatus() > Orders.TO_BE_CONFIRMED){
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }
        //订单取消前 判断是不是在未接单的情况下进行退款操作
        if (orders.getPayStatus().equals(Orders.PAID)){
            //调用微信接口进行退款操作
/*            weChatPayUtil.refund(
                    orders.getNumber(),//分别是订单编号 退款订单编号 ， 订单金额 ，退款金额
                    orders.getNumber(),
                    new BigDecimal(0.01),
                    new BigDecimal(0.01)
                    );*/
            //设置订单支付状态
            orders.setPayStatus(Orders.REFUND);
        }
        //设置订单的取消的原因
        orders.setCancelReason("用户取消");
        orders.setStatus(Orders.CANCELLED);
        orders.setCancelTime(LocalDateTime.now());
        orderMapper.update(orders);




    }

    /**
     * 再来一单
     * @param id
     */
    @Override
    public void repetionOrder(Long id) {
        Long userId = BaseContext.getCurrentId();
        List<OrderDetail> orderDetailList = orderDetailMapper.selectByOrderId(id);

        //查询订单详情，回填购物车

        List<ShoppingCart> shoppingCartList = orderDetailList.stream().map(x -> {
            ShoppingCart shoppingCart = new ShoppingCart();
            BeanUtils.copyProperties(x, shoppingCart, "id");
            shoppingCart.setUserId(userId);
            shoppingCart.setCreateTime(LocalDateTime.now());
            return shoppingCart;
        }).collect(Collectors.toList());

        //进行批量插入
        shoppingCartMapper.insertBatch(shoppingCartList);

    }

    /**
     * 用户催单
     * @param id
     */
    @Override
    public void reminderOrder(Long id) {
        Orders ordersDB = orderMapper.getById(id);
        if (ordersDB == null) {
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        Map map = new HashMap<>();
        map.put("type", 1);//2为催单
        map.put("orderId", ordersDB.getId());
        map.put("content", "订单编号：" + ordersDB.getNumber());
        webSocketServer.sendToAllClient(JSONObject.toJSONString(map));

    }

    /// ///////////////////////////////////////////////////////////




    /**
     * 各个状态的数据统计
     * @return
     */
    @Override
    public OrderStatisticsVO statistics() {
        //待接单数量   待派送数量     派送中的数量

/*        private Integer toBeConfirmed; //待接单数量   TO_BE_CONFIRMED
        private Integer confirmed;    //待派送数量    CONFIRMED
        private Integer deliveryInProgress;    //派送中数量   DELIVERY_IN_PROGRESS
        */
        Integer toBeConfirmed = orderMapper.countStatus(Orders.TO_BE_CONFIRMED);
        Integer confirmed = orderMapper.countStatus(Orders.CONFIRMED);
        Integer deliveryInProgress = orderMapper.countStatus(Orders.DELIVERY_IN_PROGRESS);

        OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();
        orderStatisticsVO.setToBeConfirmed(toBeConfirmed);
        orderStatisticsVO.setConfirmed(confirmed);
        orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);
        return orderStatisticsVO;
    }




    /**
     * 接单
     * @param ordersConfirmDTO
     */
    @Override
    public void confirm(OrdersConfirmDTO ordersConfirmDTO) {
        Orders orders = Orders.builder()
                .id(ordersConfirmDTO.getId())
                .status(Orders.CONFIRMED)
                .build();
        orderMapper.update(orders);

    }

    /**
     * 派送订单
     * @param id
     */
    @Override
    public void delivery(Long id) {
        //首先根据id判断订单是否存在且状态为3
        Orders ordersDB = orderMapper.getById(id);
        if (ordersDB == null || ordersDB.getStatus() != Orders.CONFIRMED) {
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }

        Orders orders = Orders.builder()
                .status(Orders.DELIVERY_IN_PROGRESS)
                .id(ordersDB.getId())
                .build();

        orderMapper.update(orders);


    }

    /**
     * 完成订单
     * @param id
     */
    @Override
    public void complete(Long id) {
        //首先根据id判断订单是否存在且状态为4
        Orders ordersDB = orderMapper.getById(id);
        if (ordersDB == null || ordersDB.getStatus() != Orders.DELIVERY_IN_PROGRESS) {
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }

        Orders orders = Orders.builder()
                .status(Orders.COMPLETED)
                .id(ordersDB.getId())
                .build();

        orderMapper.update(orders);

    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     */
    @Override
    public void cancel(OrdersCancelDTO ordersCancelDTO) throws Exception {
        //首先根据id查询订单是否存在
        Orders ordersDB = orderMapper.getById(ordersCancelDTO.getId());
        if (ordersDB == null ) {
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }

        Orders orders = new Orders();

        //只需要判断支付状态，如果是已经支付的了，调用接口进行退款
        if (ordersDB.getPayStatus().equals(Orders.PAID) ) {
   /*         weChatPayUtil.refund(ordersDB.getNumber(),
                    ordersDB.getNumber(),
                    new BigDecimal(0.01),
                    new BigDecimal(0.01));*/
            orders.setPayStatus(Orders.REFUND); //设置为退款
        }
        orders.setStatus(Orders.CANCELLED);
        orders.setCancelReason(ordersCancelDTO.getCancelReason());
        orders.setCancelTime(LocalDateTime.now());
        //一定要设置id，不然查不到
        orders.setId(ordersDB.getId());
        orderMapper.update(orders);

    }



    /**
     * 拒单
     * @param ordersRejectionDTO
     */
    @Override
    public void rejection(OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        //首先根据id查询订单是否存在
        Orders ordersDB = orderMapper.getById(ordersRejectionDTO.getId());
        if (ordersDB == null ) {
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }
        Orders orders = new Orders();
        //只需要判断支付状态，如果是已经支付的了，调用接口进行退款
        if (ordersDB.getPayStatus().equals(Orders.PAID)) {
//            weChatPayUtil.refund(ordersDB.getNumber(),
//                    ordersDB.getNumber(),
//                    new BigDecimal(0.01),
//                    new BigDecimal(0.01));
            orders.setPayStatus(Orders.REFUND); //设置为退款
        }
        orders.setStatus(Orders.CANCELLED);
        orders.setRejectionReason(ordersRejectionDTO.getRejectionReason());
        orders.setCancelTime(LocalDateTime.now());
        orders.setId(ordersDB.getId());
        orderMapper.update(orders);

    }


    /**
     *  管理端订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @Override
    public PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {

        PageHelper.startPage(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());

        Page<Orders> ordersPage = orderMapper.list(ordersPageQueryDTO);
        //部分订单还需要补充信息orderDishes字符串信息
        List<OrderVO> orderVOList = getOrderVOList(ordersPage);




        return new PageResult(ordersPage.getTotal(),orderVOList);
    }


    /**
     * 承接订单搜索 ， 将orders 转化成  orderVO
     * @param ordersPage
     * @return
     */
    private List<OrderVO> getOrderVOList(Page<Orders> ordersPage) {
        List<OrderVO> orderVOS = new ArrayList<>();
        //从分页中取出结果
        List<Orders> ordersList = ordersPage.getResult();

        //不需要使用这种方式，应为不需要类型的转换
  /*      ordersList.stream().map(x ->{
            OrderVO orderVO = new OrderVO();
            BeanUtils.copyProperties(x, orderVO);
            orderVO.setOrderDishes(getOrderDishesStr(orderVO.get));
        })*/


        //如果不判断 BeanUtil会报错空指针
        if (ordersList != null && ordersList.size() > 0) {
            //进行遍历封装
            for (Orders orders : ordersList) {
                OrderVO orderVO = new OrderVO();
                BeanUtils.copyProperties(orders, orderVO);
                String orderDishesStr = getOrderDishesStr(orders);
                orderVO.setOrderDishes(orderDishesStr);
                orderVOS.add(orderVO);
            }

        }
        return orderVOS;




    }

    /**
     * 将订单详情中的菜品封装成一个字符串
     * @param orders
     * @return
     */
    private String getOrderDishesStr(Orders orders) {
        List<OrderDetail> orderDetailList = orderDetailMapper.selectByOrderId(orders.getId());

        //使用map的方式将订单详情集合转换成字符串集合
        List<String> orderDishesStr = orderDetailList.stream().map(x -> {
            String s = new String(x.getName() + "*" + x.getNumber() + ";");
            return s;
        }).collect(Collectors.toList());

        return String.join("", orderDishesStr);

    }



    /**
     * 营业额统计
     * @param begin
     * @param end
     * @return
     */
    @Override
    public TurnoverReportVO turnoverStatistics(LocalDate begin, LocalDate end) {

        //构造的日期是列表就行了
       // Map map = new HashMap<>();
        List<LocalDate> dateList  = getDateList(begin, end);

        //构造营业额序列
        //营业额按照天数统计，且状态是已完成的订单
        //sql：select count(amount) from orders where status = 5 and order_time between 2025-06-09 00:00:00 and 2025-06-09 23:59:5999999
        List<Double> turnoverList = new ArrayList<>();
        //根据日期序列查询每天的营业额
        dateList.forEach(date ->{
            Map map = new HashMap();
            //date 只有日期  2025-06-09  转换成  2025-06-09 00:00:00
            map.put("beginTime", LocalDateTime.of(date, LocalTime.MIN));
            map.put("endTime", LocalDateTime.of(date, LocalTime.MAX));
            map.put("status" , Orders.COMPLETED);
            Double turnover = orderMapper.selectByMap(map);
            //可能不会出现显示，进行空值的填充
            turnover = turnover == null ? 0.0 : turnover;
            turnoverList.add(turnover);
        });

        TurnoverReportVO turnoverReportVO = TurnoverReportVO.builder()
                .dateList(StringUtils.join(dateList, ","))
                .turnoverList(StringUtils.join(turnoverList, ","))
                .build();
        return turnoverReportVO;
    }

    /**
     * 用户统计
     * @param begin
     * @param end
     * @return
     */
    @Override
    public UserReportVO userStatistics(LocalDate begin, LocalDate end) {
        //构建日期列表 ， 新增用户数列表 ， 总用户量列表
        List<LocalDate> dateList = getDateList(begin,end);

        //新增用户数列表
        List<Integer> newUserList = new ArrayList<>();
        //select count(*) from user where create_time between  开始时间 and 结束时间
        dateList.forEach(date ->{
            Map map = new HashMap();
            map.put("beginTime", LocalDateTime.of(date, LocalTime.MIN));
            map.put("endTime", LocalDateTime.of(date, LocalTime.MAX));
            Integer userNum = userMapper.countByMap(map);
            newUserList.add(userNum);
        });


        //用户总量列表
        List<Integer> totalUserList = new ArrayList<>();
        //select count(*) from user where create_time < 当天结束时间
        dateList.forEach(date ->{
            Map map = new HashMap();
            //共用一个方法，开始时间为空，到时候直接传入
            map.put("beginTime",null);
            map.put("endTime", LocalDateTime.of(date, LocalTime.MAX));
            Integer totalUserNum = userMapper.countByMap(map);
            totalUserList.add(totalUserNum);
        });

        UserReportVO userReportVO = new UserReportVO();
        userReportVO.setDateList(StringUtils.join(dateList, ","));
        userReportVO.setNewUserList(StringUtils.join(newUserList, ","));
        userReportVO.setTotalUserList(StringUtils.join(totalUserList, ","));

        return userReportVO;
    }

    /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     */
    @Override
    public OrderReportVO ordersStatistics(LocalDate begin, LocalDate end) {
        //构建  日期列表   每日订单数列表  每日有效订单数列表
/*        private String dateList;  //日期，以逗号分隔，例如：2022-10-01,2022-10-02,2022-10-03
        private String orderCountList;    //每日订单数，以逗号分隔，例如：260,210,215
        private String validOrderCountList;    //每日有效订单数，以逗号分隔，例如：20,21,10
        private Integer totalOrderCount;    //订单总数
        private Integer validOrderCount;    //有效订单数
        private Double orderCompletionRate;*/

        Integer totalOrderCount = 0;    //订单总数
        Integer validOrderCount = 0;    //有效订单数
         //订单完成率
        Double orderCompletionRate = 0.0;
        //1.构建  日期列表
        List<LocalDate> dateList = getDateList(begin,end);
//        2.每日订单数列表
        // select count(*) from orders where order_time between -- and --

        List<Integer> orderCountList = new ArrayList<>();
        //不能使用foreach需要进行转化
        for (LocalDate date : dateList) {
            Map map = new HashMap();
            map.put("beginTime", LocalDateTime.of(date, LocalTime.MIN));
            map.put("endTime", LocalDateTime.of(date, LocalTime.MAX));
            Integer orderNum = orderMapper.countByMap(map);
            orderCountList.add(orderNum);
            //累加
            totalOrderCount += orderNum;
        }

        //3.构建有效订单数列表
        List<Integer> validOrderCountList = new ArrayList<>();

        for (LocalDate date : dateList) {
            Map map = new HashMap();
            map.put("beginTime", LocalDateTime.of(date, LocalTime.MIN));
            map.put("endTime", LocalDateTime.of(date, LocalTime.MAX));
            map.put("status" , Orders.COMPLETED);
            Integer vaildOrderNum = orderMapper.countByMap(map);
            validOrderCountList.add(vaildOrderNum);
            //累加
            validOrderCount += vaildOrderNum;
        }
        //计算订单有效比
        orderCompletionRate = validOrderCount *1.0 / totalOrderCount ;
        //进行数据的封装
        OrderReportVO orderReportVO = OrderReportVO.builder()
                .dateList(StringUtils.join(dateList, ","))
                .orderCountList(StringUtils.join(orderCountList, ","))
                .validOrderCountList(StringUtils.join(validOrderCountList, ","))
                .orderCompletionRate(orderCompletionRate)
                .totalOrderCount(totalOrderCount)
                .validOrderCount(validOrderCount)
                .build();

        return orderReportVO;
    }

    /**
     * 统计销量TOP10
     * @param begin
     * @param end
     * @return
     */
    @Override
    public SalesTop10ReportVO top10(LocalDate begin, LocalDate end) {

//        private String nameList; //商品名称列表，以逗号分隔，例如：鱼香肉丝,宫保鸡丁,水煮鱼
//        private String numberList;    //销量列表，以逗号分隔，例如：260,215,200
        /**
         *
         *    private String name;    //商品名称
         *     private Integer number;    //销量
         * select  od.name name , sum(od.number) number
         * from  orders o, order_detail od
         * where o.id = od.order_id
         * and order_time >= #{}
         * and order_time <= #{}
         * and status = #{}
         * group by o.name
         * order by number desc
         *limit 0,10
         *
         */
        //构建商品名称列表   //构建销量列表
        List<String> nameList = new ArrayList<>();
        List<Integer> numberList = new ArrayList<>();
       List<GoodsSalesDTO> goodsSalesDTOList =  orderMapper.selectTop10(begin , end , Orders.COMPLETED);

       for (GoodsSalesDTO goodsSalesDTO : goodsSalesDTOList) {
           nameList.add(goodsSalesDTO.getName());
           numberList.add(goodsSalesDTO.getNumber());
       }
        SalesTop10ReportVO salesTop10ReportVO = new SalesTop10ReportVO();

       salesTop10ReportVO.setNameList(StringUtils.join(nameList, ","));
       salesTop10ReportVO.setNumberList(StringUtils.join(numberList, ","));

       return salesTop10ReportVO;


    }

    /**
     * 抽取出来的构建日期列表的方法
     * @param begin
     * @param end
     * @return
     */
    public List<LocalDate> getDateList(LocalDate begin, LocalDate end){
        List<LocalDate> dateList = new ArrayList<>();

        //构造日期序列   如果传入的是同一天也可以进行查询
        while(begin.isEqual(end) || begin.isBefore(end)){
            dateList.add(begin);
            begin = begin.plusDays(1);
        }
        log.info("<日期序列>" + dateList);
        return dateList;
    }


}